package com.work.order.service;

import com.work.order.model.Order;
import io.seata.rm.tcc.api.BusinessActionContext;
import io.seata.rm.tcc.api.BusinessActionContextParameter;
import io.seata.rm.tcc.api.LocalTCC;
import io.seata.rm.tcc.api.TwoPhaseBusinessAction;

import java.math.BigDecimal;

@LocalTCC
public interface TccOrderService {


    /**
     * name 全局唯一; commit 就是 confirm; rollback 就是 cancel
     * @param userId
     * @param commodityCode
     * @param count
     * @param orderNo
     */
    /*@TwoPhaseBusinessAction(name = "placeOrderTcc", commitMethod = "commit", rollbackMethod = "rollback")
    boolean prepare(BusinessActionContext context,
                 @BusinessActionContextParameter(paramName = "userId")String userId,
                 @BusinessActionContextParameter(paramName = "commodityCode")String commodityCode,
                 @BusinessActionContextParameter(paramName = "count")Integer count,
                 @BusinessActionContextParameter(paramName = "orderNo")String orderNo,
                 @BusinessActionContextParameter(paramName = "orderMoney") BigDecimal orderMoney);*/

    @TwoPhaseBusinessAction(name = "placeOrderTcc", commitMethod = "commit", rollbackMethod = "rollback")
    boolean prepare(BusinessActionContext context,
                    @BusinessActionContextParameter(paramName = "order") Order order);



    boolean commit(BusinessActionContext context);


    boolean rollback(BusinessActionContext context);

}
